package com.ruoyi.common.exception;
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;

import java.util.Map;
import java.util.Objects;

public abstract class Assert<E extends RuntimeException> {

    abstract E throwException(String errorMsg);


    public void isTrue(boolean expression, String errorMsgTemplate, Object... params) {
        if (expression) {
            return;
        }
        String errorMsg = StrUtil.format(errorMsgTemplate, params);
        throwException(errorMsg);
    }


    public void isFalse(boolean expression, String errorMsgTemplate, Object... params) {
        isTrue(!expression, errorMsgTemplate, params);
    }


    public void isNull(Object object, String errorMsgTemplate, Object... params) {
        isTrue(Objects.isNull(object), errorMsgTemplate, params);
    }


    public void notNull(Object object, String errorMsgTemplate, Object... params) {
        isTrue(Objects.nonNull(object), errorMsgTemplate, params);
    }


    public void notEmpty(CharSequence text, String errorMsgTemplate, Object... params) {
        isTrue(StrUtil.isNotEmpty(text), errorMsgTemplate, params);
    }


    public void notBlank(CharSequence text, String errorMsgTemplate, Object... params) {
        isTrue(StrUtil.isNotBlank(text), errorMsgTemplate, params);
    }


    public void notContain(String textToSearch, String substring, String errorMsgTemplate, Object... params) {
        isTrue(!StrUtil.contains(textToSearch, substring), errorMsgTemplate, params);
    }

    public void notEmpty(Object[] array, String errorMsgTemplate, Object... params) {
        isTrue(ArrayUtil.isNotEmpty(array), errorMsgTemplate, params);
    }

    public void noNullElements(Object[] array, String errorMsgTemplate, Object... params) {
        isTrue(!ArrayUtil.hasNull(array), errorMsgTemplate, params);
    }


    public void notEmpty(Iterable collection, String errorMsgTemplate, Object... params) {
        isTrue(CollUtil.isNotEmpty(collection), errorMsgTemplate, params);
    }


    public void notEmpty(Map map, String errorMsgTemplate, Object... params) {
        isTrue(MapUtil.isNotEmpty(map), errorMsgTemplate, params);
    }


    public void isInstanceOf(Class<?> type, Object obj, String errorMsgTemplate, Object... params) {
        notNull(type, "Type to check against must not be null");
        isTrue(type.isInstance(obj), errorMsgTemplate, params);
    }

    public void isAssignable(Class<?> superType, Class<?> subType, String errorMsgTemplate, Object... params) {
        notNull(superType, "Type to check against must not be null");
        isTrue(Objects.nonNull(subType) && superType.isAssignableFrom(subType), errorMsgTemplate, params);
    }

    public void notEquals(Object obj1, Object obj2, String errorMsgTemplate, Object... params) {
        isTrue(!Objects.equals(obj1, obj2), errorMsgTemplate, params);
    }


    public void equals(Object obj1, Object obj2, String errorMsgTemplate, Object... params) {
        isTrue(Objects.equals(obj1, obj2), errorMsgTemplate, params);
    }

}

